package com.sam.im.heiqun.callmain;

import android.util.Log;

import org.json.JSONObject;
import org.webrtc.SdpObserver;
import org.webrtc.SessionDescription;

import io.socket.client.Ack;

import static com.sam.im.heiqun.app.App.pc;
import static com.sam.im.heiqun.app.App.socket;

/**
 * Created by jack on 2017-07-15.
 */

public class RtcSdpObserver implements SdpObserver {
    public static String destid ;
    /**
     * offer创建成功时
     * @param sessionDescription
     */
    @Override
    public void onCreateSuccess(SessionDescription sessionDescription) {
        try{
            //设置本地dsp
            pc.setLocalDescription(this,sessionDescription);
            //发送offer给对方
            JSONObject payload = new JSONObject();
            payload.put("type", sessionDescription.type.canonicalForm());
            payload.put("sdp", sessionDescription.description);
            String content=payload.toString();
           // Log.i("info","=======RtcSdpObserver");
            JSONObject msg=IMMessage.createSimpleMsg(content,47);
            socket.emit("chat", msg, new Ack() {
                @Override
                public void call(Object... args) {
                    Log.i("log","offer sent");
                }
            });
        }catch (Exception e){
            //System.out.println("error.."+e.toString());
        }

    }

    @Override
    public void onSetSuccess() {

    }

    @Override
    public void onCreateFailure(String s) {

    }

    @Override
    public void onSetFailure(String s) {

    }
}
